package com.wm.android.mydemos.tools;

import com.wm.android.mydemos.MyDemosApplication;
import com.wm.android.mydemos.R;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

public class ImageUtility {
	
	public static Bitmap generateImage(String content, int width, int height){
		
		int[] mColorArray = new int[width*height];
		for(int i=0; i<mColorArray.length; i++){
			mColorArray[i] = R.color.black;
		}
		
		Paint mPaint = new Paint();
		mPaint.setColor(MyDemosApplication.getInstance().getResources().getColor(R.color.white));
		mPaint.setTextSize(30);
		
		Bitmap mBitmap = Bitmap.createBitmap(mColorArray, width, height, Bitmap.Config.ARGB_8888);
//		must use dulicate bitmap otherwise occurs 'Immutable bitmap passed to Canvas constructor'
		Bitmap mNewBitmap = mBitmap.copy(Bitmap.Config.ARGB_8888, true);
		
		Canvas mCanvas = new Canvas(mNewBitmap);
		mCanvas.drawText("NO."+content, width/2, height/2, mPaint);
		mCanvas.save(Canvas.ALL_SAVE_FLAG);
		mCanvas.restore();
		return mNewBitmap;
	}
}
